﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using GalaSoft.MvvmLight.Command;
using System.Windows.Controls;

namespace Veralkohol.Commons
{
    public class VMAbstract : INotifyPropertyChanged, INotifyPropertyChanging
    {
        #region RelayCommandCreate<EventArgs>

        protected RelayCommand<T> NewRCommand<T>(RelayCommand<T> r, Action<T> a)
        {

            if (r == null) r = new RelayCommand<T>(a);
            return r;
        }

        #endregion

        #region RelayCommandCreate

        protected RelayCommand NewRCommand(RelayCommand r, Action a)
        {
            if (r == null) r = new RelayCommand(a);
            return r;
        }

        #endregion

        #region PropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region PropertyChanging

        public event PropertyChangingEventHandler PropertyChanging;
        protected void NotifyPropertyChanging(String propertyName)
        {
            PropertyChangingEventHandler handler = PropertyChanging;
            if (null != handler)
            {
                handler(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        #endregion
    }
}
